/**
 * <AiRmob-Framework; A simple augmented reality framework for android >
    Copyright (C) <2012>  <AiRmob Team>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package rendercomponents;

import java.util.LinkedList;

public class ModelGroup extends Object {

	String path;

	protected LinkedList<ModelCustom> models;

	protected boolean hasTransparentModel = false;

	/**
	 * Constructs a modelGroup out of a external model-file. A modelGroup
	 * consists of a LinkedList of models. Therefore multiple materials (and
	 * textures) are possible in a modelGroup (if existent in the external
	 * model-file)
	 * 
	 * @param r
	 *            the used renderer
	 * @param path
	 *            the path where the file that shall be imported is located on
	 *            the device
	 * @param type
	 *            the type of the model-file
	 */
	public ModelGroup(Renderer r, String path, ModelFileTypes type) {
		this.path = path;
		this.type = 8;
		this.models = new LinkedList<ModelCustom>();
		if (type == ModelFileTypes.OBJ)
			r.resourceManager.loadModelGroupFromOBJ(path, this,
					r.settings.useVBO);

		for (Model3D m : models) {
			if (m.isTransparent())
				hasTransparentModel = true;
		}

	}

	/**
	 * 
	 * @param index
	 *            the position of the model in the list
	 * @return the modelCustom found under index
	 */
	public ModelCustom getModel(int index) {
		return models.get(index);
	}

	/**
	 * 
	 * @param name
	 *            the name of the model. Will be the name of the material used
	 *            for this model.
	 * @return the modelCustom found under this name. Null if none was found.
	 */
	public ModelCustom getModel(String name) {
		for (int i = 0; i < models.size(); i++) {
			if (models.get(i).name == name)
				return models.get(i);
		}
		return null;
	}

}
